<%@ page import="com.esurvey.core.*" %>
<html>
<head>
</head>
<body>
	<%
		if ((request.getParameter("username") != null) && (request.getParameter("password") != null)) {
			String login = request.getParameter("username");
			String pass = request.getParameter("password");
			try {
				boolean ok = eSurveyPersistence.canLogin(login,pass);
				if (ok) {
					session.setAttribute("username",login);
					User u = eSurveyPersistence.loadUser(login);
					if (u.isAdmin()){
						session.setAttribute("kind","admin");
					} else {
						session.setAttribute("kind","user");
					}
					response.sendRedirect("userMySurveys.jsp");
				} else if ( (eSurveyPersistence.loginOK(login,pass)) && (!eSurveyPersistence.emailVerified(login)) ) {
					response.sendRedirect("login.jsp?loginverified=false");
				} else {
					response.sendRedirect("login.jsp?loginok=false");
				}
			} catch (Exception e) {
				response.sendRedirect("error.jsp?exception="+e);
			}
		} else {
			response.sendRedirect("login.jsp");
		}
	%>
</body>
</html>
